{include file="public/header" /}



<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <div class="subject">
                <h3>服务设备管理</h3>
                <h5></h5>
            </div>
            {include file="public/admin_items" /}
        </div>
    </div>
    <div class="fixed-empty"></div>

    <form method="get" name="formSearch" id="formSearch">
        <div class="ds-search-form">
            <dl>
                <dt>名称</dt>
                <dd><input type="text" value="{$Request.param.title}" name="title" class="txt"></dd>
            </dl>
            <dl>
                <dt>分类</dt>
                <select name="search_gc_id1" id="search_gc_id1">
                    <option value="">{$Think.lang.ds_please_choose}</option>
                    {notemtpy name="$class_list"}
                    {foreach $class_list as $key => $val}
                    <option value="{$val.gc_id}"}>{$val.gc_name}</option>
                    {/foreach}
                    {/notempty}
                </select>
                <select name="search_gc_id2" id="search_gc_id2">
                    <option value="">{$Think.lang.ds_please_choose}</option>
                </select>
                <select name="search_gc_id3" id="search_gc_id3">
                    <option value="">{$Think.lang.ds_please_choose}</option>
                </select>
            </dl>
            <dl>
                <dt>状态</dt>
                <dd>
                    <select name="search_status" id="">
                        <option value="">全部</option>
                        <option value="1" {$Request.param.search_status == 1 ? 'selected' : ''}>启用</option>
                        <option value="2" {$Request.param.search_status == 2 ? 'selected' : ''}>禁用</option>
                    </select>
                </dd>
                <dd><input type="submit" class="btn btn-small" value="{$Think.lang.ds_search}"></dd>

                {if $title != '' || $search_gc_id1 !='' || $search_gc_id2 != '' || $search_gc_id3 != ''}
                <dd><input type="button" id="celsearch" class="btn btn-small" value="取消搜索"></dd>
                {/if}
                <script>
                    // todo 取消搜索
                    $("#celsearch").click(function (){
                        $("[name='title']").val('');
                        $("[name='search_status']").val('');
                        $("[name='search_gc_id1']").val('');
                        $("[name='search_gc_id2']").val('');
                        $("[name='search_gc_id3']").val('');
                        $('#formSearch').submit()
                    })
                </script>
            </dl>

            <div class="btn_group">
            </div>
        </div>
    </form>
    <table class="ds-default-table">
        <thead>
        <tr class="thead">
            <th class="w48">序号</th>
            <th>设备名称</th>
            <th>分类&品牌</th>
            <th>规格</th>
            <th>型号</th>
            <th>状态</th>
            <th class="w200 align-center">创建时间</th>
            <th class="w200 align-center">{$Think.lang.ds_handle}</th>
        </tr>
        <tbody>
        {notempty name="equipment_list"}
        {foreach name="equipment_list" item="question" key="key"}
        <tr id="ds_row_{$question.id}">
            <td>{$key+1}</td>
            <td>{$question.goods_name}</td>
            <td>
                <p>{$question.class_name}</p>
                <p class="goods-brand">{$Think.lang.ds_brand}：{$question.b_name}</p>
            </td>
            <td>{$question.specifications}</td>
            <td>{$question.type_model}</td>
            <td>
                {if $question.status == 1}
                   启用
                {else/}   
                   禁用
                {/if}
            </td>
            <td>{$question.created_at}</td>
            <td>
                    {if $question.status == 1}
                    <a href="javascript:void(0);"
                       onclick="ds_ajaxget_confirm('{:url('Equipment/equipment_status',['id'=>$question.id,'status'=>$question.status])}','确定要禁用吗？');"
                       class="dsui-btn-del">禁用</a>
                    {else/}   
                    <a href="javascript:void(0);"
                       onclick="ds_ajaxget_confirm('{:url('Equipment/equipment_status',['id'=>$question.id,'status'=>$question.status])}','确定要开启吗？');"
                       class="dsui-btn-edit">开启</a>
                    {/if}

                    <a href="{:url('Equipment/equipment_edit',['id'=>$question.id])}" class="dsui-btn-edit"><i class="iconfont"></i>{$Think.lang.ds_edit}</a>
                    <a href="javascript:void(0);"
                       onclick="ds_ajaxget_confirm('{:url('Equipment/equipment_del',['id'=>$question.id])}','确定要删除吗？');"
                       class="dsui-btn-del"><i class="iconfont"></i>删除</a>
            </td>
        </tr>
        {/foreach}
        {else /}
        <tr class="no_data">
            <td colspan="10">{$Think.lang.ds_no_record}</td>
        </tr>
        {/notempty}
        </thead>
    </table>
    {$show_page}
</div>
<script src="{$Think.ADMIN_SITE_ROOT}/js/question.js"></script>
<script type="text/javascript" src="{$Think.ADMIN_SITE_ROOT}/js/jquery.edit.js" charset="utf-8"></script>
<script type="text/javascript">

    function getGcId1(gc_id1, select_id)
    {
        var select_od = select_id;
        $.ajax({
            type : "GET",
            contentType: "application/json;charset=UTF-8",
            url : ADMINSITEURL+"/Question/getClass.html?gc_id=" + gc_id1,
            success : function(result) {
                result = JSON.parse( result );
                var html = '<option value="">选择分类</option>';
                for(var i=0;i<result.length;i++){
                    if (result[i].gc_id == select_id) {
                        html += '<option selected value="'+ result[i].gc_id +'">'+ result[i].gc_name +'</option>'
                    } else {
                        html += '<option value="'+ result[i].gc_id +'">'+ result[i].gc_name +'</option>'
                    }
                }
                $('#search_gc_id2').html(html)
            },
            //请求失败，包含具体的错误信息
            error : function(e){
                console.log(e.status);
                console.log(e.responseText);
            }
        });
    }

    function getGcId2(gc_id1, select_id)
    {
        $.ajax({
            type : "GET",
            contentType: "application/json;charset=UTF-8",
            url : ADMINSITEURL+"/Question/getClass.html?gc_id=" + gc_id1,
            success : function(result) {
                result = JSON.parse( result );
                var html = '<option value="">选择分类</option>';
                for(var i=0;i<result.length;i++){
                    if (result[i].gc_id == select_id) {
                        html += '<option selected value="'+ result[i].gc_id +'">'+ result[i].gc_name +'</option>'
                    } else {
                        html += '<option value="'+ result[i].gc_id +'">'+ result[i].gc_name +'</option>'
                    }
                }
                $('#search_gc_id3').html(html)
            },
            //请求失败，包含具体的错误信息
            error : function(e){
                console.log(e.status);
                console.log(e.responseText);
            }
        });
    }
    //获取下级分类
    $('#search_gc_id1').on('change',function () {
        var gc_id1 = $(this).val();
        getGcId1(gc_id1)
    })

    $('#search_gc_id2').on('change',function () {
        var gc_id2 = $(this).val();
        getGcId2(gc_id2)
    })
</script>
{if $Request.param.search_gc_id1}
<script>

    // 编辑初始化，处理分类选中的问题
        var gc_id1 = '{$Request.param.search_gc_id1}';
        var gc_id2 = '{$Request.param.search_gc_id2}';
        var gc_id3 = '{$Request.param.search_gc_id3}';
        getGcId1(gc_id1, gc_id2)
        getGcId2(gc_id2, gc_id3)
</script>
{/if}
